let questionsApp = new Vue({
    el: '#questionsApp',
    data: {
        questions: [],
        navigatepageNums: [],
        prePageNum: 0,
        nextPageNum: 0,
        maxPagesNum: 9999,
        currentPageNum: 0,
    },
    methods: {
        loadMyQuestions: function (page) {
            // alert("准备开始")
            if (page < 1) {
                alert("当前已经是第一页！")
                return;
            }
            if (page > this.maxPagesNum) {
                alert("当前已经是最后一页！")
                return;
            }
            if (page == this.currentPageNum) {
                return;
            }
            $.ajax({
                url: '/api/v1/questions/my-list',
                data: 'page=' + page,
                success: function (json) {
                    // console.log(json.data);
                    if (json.state == 2000) {
                        let list = json.data.list
                        let questions = []
                        let statusClasses = ['badge-warning', 'badge-info', 'badge-success']
                        let statusTexts = ['未回复', '已回复', '已解决']
                        for (let i = 0; i < list.length; i++) {
                            let question = {}
                            question.title = list[i].title
                            question.statusClass = statusClasses[list[i].status]
                            question.statusText = statusTexts[list[i].status]
                            question.id = list[i].id
                            question.content = list[i].content
                            question.userNickName = list[i].userNickName
                            question.hits = list[i].hits

                            question.createdTimeText = getTimeText(list[i].createdTime)
                            question.tagImageUrl = 'img/tags/' + list[i].tags[0].id + '.jpg'
                            question.tags = list[i].tags
                            questions[i] = question
                        }


                        questionsApp.questions = questions
                        questionsApp.navigatepageNums = json.data.navigatepageNums
                        questionsApp.prePageNum = json.data.prePage
                        let nextPageNum = json.data.nextPage
                        if (json.data.nextPage == 0 && json.data.pages > 0) {
                            nextPageNum = json.data.pages + 1
                        }
                        questionsApp.nextPageNum = nextPageNum
                        questionsApp.maxPagesNum = json.data.pages
                        questionsApp.currentPageNum = json.data.pageNum
                    }
                }
            })
        }
    },
    created: function () {
        this.loadMyQuestions(1)
    }
})